#ifndef __SINGLETON_H__
#define __SINGLETON_H__

#include <pthread.h>

class qMutex
{
public:
	qMutex()
	{
		pthread_mutex_init(&mt_, nullptr);
	}

	~qMutex()
	{
		pthread_mutex_destroy(&mt_);
	}

	void lock()
	{
		pthread_mutex_lock(&mt_);
	}

	void unlock()
	{
		pthread_mutex_unlock(&mt_);
	}
private:
	pthread_mutex_t mt_;
};

template<class T>
class qSingleton
{
public:
	static T* getInstance()
	{
      if(!sington_)
      {
			  sington_ = new T;
      }

		return sington_;
	}

	static void delInstance()
	{
		if (sington_)
		{
			delete sington_;
			sington_ = nullptr;
		}
	}
protected:
	qSingleton(){}

private:
	qSingleton(const qSingleton&);
	qSingleton& operator=(const qSingleton&);


	static T* sington_;
};

template<class T>
T* qSingleton<T>::sington_ = nullptr;

#endif
